﻿using MongoDB.Bson;
using MongoDB.Driver;
using YmtSystem.CrossCutting;

namespace YmtAuth.Repository.Mongodb
{
    public class MongodbContext_NewCore
    {
        private MongoClient client;           

        public MongodbContext_NewCore(MongoClient client)
        {
            YmtSystemAssert.AssertArgumentNotNull(client, "mongo client instance cant'null");          
           
            this.client = client;                 
        }
       
        private IMongoCollection<TEntity> _GetCollection<TEntity>(string dbName, string collectionName)
        {
            YmtSystemAssert.AssertArgumentNotEmpty(dbName, "数据库名不能为空");
            YmtSystemAssert.AssertArgumentNotEmpty(collectionName, "集合名不能为空");
            return this.Database(dbName).GetCollection<TEntity>(collectionName);
        }
        public IMongoCollection<BsonDocument> GetCollection(string dbName, string collectionName)
        {
            YmtSystemAssert.AssertArgumentNotEmpty(dbName, "数据库名不能为空");
            YmtSystemAssert.AssertArgumentNotEmpty(collectionName, "集合名不能为空");
            return this.Database(dbName).GetCollection<BsonDocument>(collectionName);
        }
      
        public IMongoDatabase Database(string dbName)
        {
            YmtSystemAssert.AssertArgumentNotEmpty(dbName, "数据库名不能为空");
            return this.client.GetDatabase(dbName);
        }       
    }
}
